#include "createmeeting.h"
#include "ui_createmeeting.h"
#include <QMessageBox>
#include <QDebug>

CreateMeeting::CreateMeeting(QString sender, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CreateMeeting), sender(sender)
{
    ui->setupUi(this);
    ui->lw_users->setSelectionMode(QAbstractItemView::ExtendedSelection);
}

CreateMeeting::~CreateMeeting()
{
    delete ui;
}

void CreateMeeting::onAllUsers(QStringList users)
{
    for (auto user : users)
    {
        if (user == this->sender) continue;
        QListWidgetItem *item = new QListWidgetItem(user);
        item->setTextAlignment(Qt::AlignCenter);
        ui->lw_users->addItem(item);
    }
}

void CreateMeeting::on_btn_create_clicked()
{
    QString meetingName = ui->le_name->text();
    if (meetingName.isEmpty())
    {
        QMessageBox::warning(this, "创建", "会议名不能为空");
        return ;
    }
    QList<QListWidgetItem*> selectedItems = ui->lw_users->selectedItems();
    QStringList users;
    users.push_back(sender);
    for (auto user : selectedItems)
    {
        users.push_back(user->text());
        //qDebug() << user->text();
        //qDebug() << test;
    }
    emit meeting(users, meetingName);
    this->deleteLater();
}
